<?php
/**
 *
 * User: wangshuai
 * Date: 2021/8/6
 * Time: 17:20
 * Email: <1076890579@qq.com>
 */

class Container
{
    public $bindings = [];

    public function bind($key, Closure $closure) {
        $this->bindings[$key] = $closure;
    }

    public function make($key) {
        $new = $this->bindings[$key];
        return $new;
    }
}

$app = new Container();
$app->bind('mysql', function () {
    return new DbMysql('host', 'name', 'pwd');
});
$app->bind('redis', function () {
    return new DbMysql('host', 'name', 'pwd');
});
$app->bind('controller', function () use ($app) {
    return new Controller($app->make('mysql'), $app->make('redis'));
});

$controller = $app->make('controller');
var_dump($controller->action());